/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.persistence.hibernate.criteria;

import java.util.Map;

import com.genia.toolbox.basics.manager.CollectionManager;
import com.genia.toolbox.persistence.basis.criteria.SimpleCriteriaType;
import com.genia.toolbox.persistence.hibernate.bean.Queryable;
import com.genia.toolbox.persistence.hibernate.bean.impl.QueryableDisplayObject;

/**
 * This class represents a queried column in a Criteria for the hibernate
 * implementation.
 * 
 * @param <TYPE>
 *          The type of the column
 */
public class HibernateCriteriaType<TYPE>
    extends SimpleCriteriaType<TYPE>
    implements Queryable
{

  /**
   * the alias of this column used in the hibernate query.
   */
  private final transient String alias;



  /**
   * the constructor of <code>HibernateCriteriaType</code>.
   * 
   * @param type
   *          the class of the type of the column
   * @param alias
   *          the alias of this column used in the hibernate query
   */
  public HibernateCriteriaType(final Class<TYPE> type, final String alias)
  {
    super(type);
    this.alias = alias;
  }



  /**
   * getter for the alias property.
   * 
   * @return the alias
   */
  public String getAlias()
  {
    return alias;
  }



  /**
   * append to stringBuilder the part of the query represented by this object.
   * 
   * @param canHaveParameter
   *          can this part of the query use named parameters?
   * @param collectionManager
   *          The <code>CollectionManager</code> that allow us to perform
   *          joins
   * @param criteria
   *          the <code>HibernateCriteria</code> the represents the all query
   * @param stringBuilder
   *          the <code>StringBuilder</code> to append to.
   * @param queryableDisplayObject
   *          the <code>DisplayObject</code> that allows to convert this
   *          <code>Queryable</code> to a <code>String</code>
   */
  public void appendQuery(final boolean canHaveParameter, final CollectionManager collectionManager, final HibernateCriteria<?> criteria, final StringBuilder stringBuilder,
      final QueryableDisplayObject queryableDisplayObject)
  {
    stringBuilder.append(getType().getCanonicalName());
    stringBuilder.append(" AS ");
    stringBuilder.append(getAlias());
  }



  /**
   * Fill the parameters <code>Map</code> with the constants elements of this
   * query.
   * 
   * @param parameters
   *          the <code>Map</code> to be filled
   */
  public void fillParameters(final Map<String, Object> parameters)
  {
    // Do nothing
  }

}
